package com.zbowen.invoice.web.ivabook;

import com.zbowen.invoice.base.dto.IvaBookDto;
import com.zbowen.invoice.base.service.IvaBookService;
import com.zbowen.invoice.feign.api.IvaBookFeignApi;
import com.zbowen.invoice.feign.dto.IvaBookFeignDto;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import java.lang.reflect.InvocationTargetException;

/**
 * 远程调用controller （服务间内部调用）
 */
@RestController
public class IvaBookFeignController implements IvaBookFeignApi {

    @Autowired
    private IvaBookService ivaBookService;

    @Override
    public IvaBookFeignDto queryInvoiceStatus(String vatino) {
        IvaBookFeignDto ivaBookFeignDto = new IvaBookFeignDto();
        IvaBookDto ivaBookDto = ivaBookService.findIvaBookByVatino(vatino);
        try {
            BeanUtils.copyProperties(ivaBookDto, ivaBookFeignDto);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
        return ivaBookFeignDto;
    }
}
